<template>
	<uni-popup ref="popup" type="bottom" @change="change">
		<view class="SongMenu">
			<view class="song-head" >
				播放列表
			</view>
			<!-- 歌曲列表 -->
			<view class="songList">
				<view v-for="(item,index) in globalData.songlist">
					<view class="flex-center">{{index+1}}</view>
					<view @click="getMusicPlay(item.mid)">
						<view :class="{focusSong:globalData.data.value.songmid==item.mid}">{{item.name}}</view>
						<view>{{item.singer[0].name}} - {{item.album.name}}</view>
					</view>
					<view class="flex-center">
						<uni-icons type="folder-add"></uni-icons>
					</view>
				</view>
			</view>
		</view>
	</uni-popup>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		GetMusicPlay
	} from "@/utils/MusicAPI.js"
	const popup = ref(null)
	const globalData = getApp().globalData
	//获取歌曲播放链接
	const getMusicPlay = (songmid) => {
		GetMusicPlay(songmid).then(res => {
			if (res.data.data.playUrl[songmid].url == "") {
				uni.showToast({
					icon: "none",
					title: "此歌曲吗有播放链接呢试试其他的吧 (●'◡'●)",
				});
			} else {
				toMusicPlay(res.data.data.playUrl[songmid].url, songmid)
			}
		}).catch(err => {
			console.log("获取歌曲播放链接", err)
		})
	}
	//跳转音乐播放页
	const toMusicPlay = (playUrl, songmid) => {
		const data = getApp().globalData.data
		data.value.playUrl = playUrl
		data.value.songmid = songmid
		uni.navigateTo({
			url: "/pages/MusicPlay/MusicPlay"
		})
	}

	const change = (e) => {
		console.log(e)
	}
	
	defineExpose({
		popup
	})
</script>

<style scoped>
	.SongMenu {
		height: 70vh;
		background-color: #2e2e38;
		border-radius: 20px 20px 0 0;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		padding: 20rpx;
		box-sizing: border-box;
	}

	.song-head {
		height: 10%;
	}

	.songList {
		height: 90%;
		overflow-y: auto;
	}

	.songList>view {
		display: grid;
		grid-template-columns: 10% 70% 20%;
		box-sizing: border-box;
		height: 100rpx;
		margin-bottom: 20rpx;
		color: #7a7a7a;
	}

	.songList>view>view:nth-child(2) {
		display: flex;
		flex-direction: column;
		justify-content: center;

	}

	.songList>view>view:nth-child(2)>view:nth-child(1) {
		color: #dddddd;
	}

	.songList>view>view:nth-child(2)>view:nth-child(2) {
		text-indent: 1em;
		margin-top: 0.1em;
		font-size: 0.9em;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
	}
</style>